﻿var app = angular.module('myAPP');
app.controller('HomeController', ['$scope', '$rootScope', 'setLanguageFactory', '$http', '$location', '$sce',
function ($scope, $rootScope, setLanguageFactory, $http, $location, $sce) {



    $scope.init = function () {
        $scope.lLanguage = setLanguageFactory.varlogin($scope.$parent.language);
        $scope.lRegister = setLanguageFactory.varRegister($scope.$parent.language);
        $scope.Label1 = setLanguageFactory.testVar1("en");
        $scope.Label2 = setLanguageFactory.testVar1("th");
        $scope.visible = true;
        //console.log($location.path());
        
        $scope.flatLogin = false;
        $scope.docheckLogin2();
        $scope.$parent.doselHome();
        $scope.myInterval = 2000;

        $scope.slides = [
        {
            //image: '/PaydSystem/Images/PaydImages/head1.jpg',
            image: '/Images/PaydImages/head1.jpg',
            title: 'head1'
        },
        {
            //image: '/PaydSystem/Images/PaydImages/head2.jpg',
            image: '/Images/PaydImages/head2.jpg',
            title: 'head2'
        },
        {
            //image: '/PaydSystem/Images/PaydImages/head3.jpg',
            image: '/Images/PaydImages/head3.jpg',
            title: 'head3'
        }
        //        {
        //            image: 'http://lorempixel.com/400/200/people'
        //        }
      ];
    };

    $scope.initDetail = function () {

        $scope.data = [
          { feedCol1: "la khao tom mat sai kluai mae sot mu krop plaza. Ko tao tam som o nam pu kun yo nai si khrong.Ka tao tam som o nampu kun you."
            , feedCol2: "la khao tom mat sai kluai mae sot mu krop nana plaza.la khao tom mat sai kluai mae sot mu krop nana plaza."
            , feedCol3: "la khao tom mat sai kluai mae sot mu krop plaza. Ko tao tam som o nam pu kun yo nai si khrong mu that thailand centre."
          }
        ];
        $scope.feedCol1 = "la khao tom mat sai kluai mae sot mu krop plaza. Ko tao tam som o nam pu kun yo nai si khrong.Ka tao tam som o nampu kun you.";
        $scope.feedCol2 = "la khao tom mat sai kluai mae sot mu krop nana plaza.la khao tom mat sai kluai mae sot mu krop nana plaza.";
        $scope.feedCol3 = "la khao tom mat sai kluai mae sot mu krop plaza. Ko tao tam som o nam pu kun yo nai si khrong mu that thailand centre.";
        $scope.feedCol1 = $sce.trustAsHtml($scope.feedCol1);
        $scope.feedCol2 = $sce.trustAsHtml($scope.feedCol2);
        $scope.feedCol3 = $sce.trustAsHtml($scope.feedCol3);
    };



    $scope.toggle = function () {
        $scope.visible = !$scope.visible;
    }

    $scope.docheckLogin2 = function () {

        $http({
            url: "../../PaydSw.asmx/CheckUserExistLogin",
            dataType: 'json',
            method: 'POST',
            data: '',
            headers: {
                "Content-Type": "application/json"
            }
        }).success(function (response) {
            var data = JSON.parse(response.d);

            if (data.Result != 0) {

                $scope.flatLogin = true;
            }
            else {
                $scope.flatLogin = false;

            }
        })
        .error(function (error) {
            var ErrorMessage = 'error at CheckUserExistLogin at HomeController ' + error.ExceptionType + ' ' + error.Message + ' ' + error.StackTrace;
            alert(ErrorMessage);
            $scope.activeHomeIcon = true;
            $scope.activeSelHomeIcon = true;
            $location.path('/home');
        });
    }

    $scope.docheckLogin = function () {
        $scope.$parent.doselProfile();
        $http({
            url: "../../PaydSw.asmx/CheckUserExistLogin",
            dataType: 'json',
            method: 'POST',
            data: '',
            headers: {
                "Content-Type": "application/json"
            }
        }).success(function (response) {
            var data = JSON.parse(response.d);

            if (data.Result != 0) {
                $location.path('/Profile');
            }
            else {

                $location.path('/login');
            }
        })
        .error(function (error) {
            var ErrorMessage = 'error at CheckUserExistLogin at HomeController ' + error.ExceptionType + ' ' + error.Message + ' ' + error.StackTrace;
            alert(ErrorMessage);
            $scope.activeHomeIcon = true;
            $scope.activeSelHomeIcon = true;
            $location.path('/home');
        });
    }

    $scope.docheckRegister = function () {
        $scope.$parent.doselProfile();
        $http({
            url: "../../PaydSw.asmx/CheckUserExistLogin",
            dataType: 'json',
            method: 'POST',
            data: '',
            headers: {
                "Content-Type": "application/json"
            }
        }).success(function (response) {
            var data = JSON.parse(response.d);

            if (data.Result != 0) {
                $location.path('/Profile');
            }
            else {
                $location.path('/register');
            }
        })
        .error(function (error) {
            var ErrorMessage = 'error at CheckUserExistLogin at HomeController ' + error.ExceptionType + ' ' + error.Message + ' ' + error.StackTrace;
            alert(ErrorMessage);
            $scope.activeHomeIcon = true;
            $scope.activeSelHomeIcon = true;
            $location.path('/home');
        });
    }

} ])



